import { View } from "@tarojs/components";

import "./index.scss";

import Taro from "@tarojs/taro";

import { observer, inject } from "mobx-react";

export default inject("store")(
  observer((props) => {
    // 拿到属于用户模块的store
    const { userStore } = props.store;
    const { desc } = props;
    const getUserInfo = (e) => {
      Taro.getUserProfile({ desc: desc || "请求登录" }).then((res) => {
        const usi = res.userInfo;
        // 这里调接口更新用户数据
        const data = {
          avatar: usi.avatarUrl,
          nick_name: usi.nickName,
        };
        userStore.updateUserInfo(data);
      });
      return (
        !userStore.userInfo.avatar && (
          <View className="user_login" onClick={getUserInfo}></View>
        )
      );
    };
  })
);
